package com.leetcode;


import java.util.HashMap;
import java.util.Map;

/**
 * Created by yijy on 2018/3/16.
 *
 */
public class TwoSumSolution {

    public static void main(String[] args) {
        int[] nums = {2, 7, 11, 15};
        new TwoSumSolution().twoSum(nums,10);
    }

    private int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> map = new HashMap();
        for(int i=0;i<nums.length;i++){
            if(map.containsKey(target-nums[i])){
                return new int[]{map.get(target-nums[i]), nums[i]};
            }
            map.put(nums[i],i);
        }

        throw new RuntimeException("two sum is not give target");
    }

}
